var e = require("../../3D336854875DE5CF5B550053BF4D6824.js"), o = null;

Page({
    data: {
        type: "",
        filePath: "",
        name: "",
        value: "",
        code: "",
        year: "",
        landmark: "",
        isShare: 0,
        imgUrl: "",
        aiResultStr: ""
    },
    onLoad: function(e) {
        if (console.log("options:"), console.log(e), null != e.filePath) {
            var o = e.type, n = e.filePath;
            this.recognize(n, o);
        }
        this.loadInterstitialAd();
    },
    loadInterstitialAd: function() {
        wx.createInterstitialAd && ((o = wx.createInterstitialAd({
            adUnitId: "adunit-34c1ba75d34ffbde"
        })).onLoad(function() {
            console.log("ad onLoad event emit");
        }), o.onError(function(e) {
            console.log("ad onError event emit", e);
        }), o.onClose(function(e) {
            console.log("ad onClose event emit", e);
        }));
    },
    showInterstitialAd: function() {
        o && o.show().catch(function(e) {
            console.log("插屏广告显示失败"), console.error(e);
        });
    },
    recognize: function(o, n) {
        var t = this, a = this;
        e.recognize(o, n).then(function(e) {
            if (e) {
                console.log("ai result:", e), a.setData({
                    imgUrl: e.imgUrl
                });
                var o = e.aiResult[0], n = JSON.stringify(o);
                a.setData({
                    aiResultStr: n
                }), console.log("aidata", o), (a.data.type = "landmark") && a.setData({
                    landmark: o.name
                }), (a.data.type = "money") && a.setData({
                    name: o.currencyName,
                    value: o.currencyDenomination,
                    code: o.currencyCode,
                    year: o.year
                }), a.showInterstitialAd();
            } else console.log("结果有问题"), wx.showToast({
                title: "无法识别"
            });
        }).catch(function(e) {
            console.log("errinfo"), console.log(e), t.setData({
                filePath: ""
            }), wx.showModal({
                title: "提示",
                content: e.message,
                showCancel: !1,
                complete: function(e) {
                    e.confirm && wx.navigateBack();
                }
            });
        });
    },
    chooseImage: function() {
        var e = this;
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "camera", "album" ],
            success: function(o) {
                console.log("choose image success:"), console.log(o);
                var n = o.tempFilePaths[0];
                e.setData({
                    filePath: n
                }), e.recognize(n);
            },
            fail: function(e) {
                console.log("取消了");
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onShareAppMessage: function() {}
});